import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:xiandou/Common.dart';
import 'package:xiandou/common/Global.dart';
import 'package:xiandou/login/ChangePwdController.dart';
import 'package:xiandou/login/Login.dart';
import 'package:xiandou/models/Index.dart';

class SettingrScreen extends StatefulWidget {
  @override
  State<StatefulWidget> createState() =>  SettingrScreenState();
}

class SettingrScreenState extends State<SettingrScreen> {

  void _userLogoutAction() {
    Global.clearProfile();
    Navigator.pushReplacement(
        context, new MaterialPageRoute(builder: (context) => LoginPage()));
  }

  void _itemSelectAction(int index) {
    if(index == 0) {
      Navigator.push(
        context,
        new MaterialPageRoute(builder: (context) => new ChangePwdController()),
      );
    }
  }

  Widget SettingCellWidget(String titleString,bool isShowArrow,int index) {
    return Expanded(
        flex: 1,
        child: GestureDetector(
          onTap:()=> _itemSelectAction(index),
          child: Container(
              child:Column(
                children: <Widget>[
                  Expanded(
                    child: ListTile(
                      leading: Text(titleString),
                      trailing: isShowArrow == true ? Icon(Icons.keyboard_arrow_right) : null,
                    ),
                  ),
                  Container(
                    padding: const EdgeInsets.only(left: 35,right: 32,bottom: 0),
                    height: 1,
                    color: Common.xdDividerColor,
                  )
                ],
              )
          ),
        )
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CupertinoNavigationBar(
        backgroundColor: Colors.white,
        middle: const Text('设置'),
      ),
      body: Center(
        child: Column(
          children: <Widget>[
            Container(
              color: Colors.white,
              height: 170,
              margin: const EdgeInsets.only(top: 15),
              child: Column(
                children: <Widget>[
                  SettingCellWidget('修改密码', true,0),
                  SettingCellWidget('清除缓存', false,1),
                  SettingCellWidget('关于我们', true,2)
                ],
              )
            ),
            GestureDetector(
              onTap: _userLogoutAction,
              child:Container(
                margin: const EdgeInsets.only(top: 160,left: 55,right: 55),
                height: 50,
                alignment: Alignment.center,
                decoration: BoxDecoration(//背景装饰
                    gradient: RadialGradient( //背景径向渐变
                        colors: [Color(0xffEE5F20), Color(0xffED4327)],
                        center: Alignment.topLeft,
                        radius: 5
                    ),
                    borderRadius: new BorderRadius.circular((20.0)),
                    boxShadow: [ //卡片阴影
                      BoxShadow(
                          color: Color(0xffEE5F20),
                          offset: Offset(2.0, 2.0),
                          blurRadius: 4.0
                      )
                    ]
                ),
                child: Text('退出登录', style: TextStyle(color: Colors.white, fontSize: 17),),
              ),
            )
          ],
        )
      ),
    );
  }
}